<?php

	// 存储密码散列
	$query  = sprintf("INSERT INTO users(name,pwd) VALUES('%s','%s');",
	            pg_escape_string($username), md5($password));
	$result = pg_query($connection, $query);
	// 发送请求来验证用户密码
	$query = sprintf("SELECT 1 FROM users WHERE name='%s' AND pwd='%s';",
	            pg_escape_string($username), md5($password));
	$result = pg_query($connection, $query);
	
	if (pg_num_rows($result) > 0) {
	    echo 'Welcome, $username!';
	} else {
	    echo 'Authentication failed for $username.';
	}

?> 